package main

import (
	"fmt"
	"io"
	"os"
)

// Author : CSR丶WARRIOR
// Time ： 2020/10/21  19:21
// TOOLS : GoLand
// FILENAME : writeData.go
// STATEMENT: 写入数据

func main() {
	var path string = "D:\\WARRIOR\\Go\\go\\src\\golang_suse\\advanceModule\\IO\\textFileHandle\\testWrite.txt"
	file, err := os.Create(path)
	if err != nil {
		fmt.Println(err)
	}
	/*_, err1 := file.WriteString("hello")
	if err1 != nil {
		fmt.Println(err1)
	}*/

	/*//write方法
	var str string = "what r u doing"
	_, err1 := file.Write([]byte(str))
	if err1 != nil {
		fmt.Println(err1)
	}*/
	s := "abc\n"
	_, _ = file.WriteString(s)
	//writeAt方法
	var strContent = "qwerty123"
	seek, err1 := file.Seek(0, io.SeekEnd)
	if err1 != nil {
		fmt.Println(err1)
	}
	at, err2 := file.WriteAt([]byte(strContent), seek)
	if err2 != nil {
		fmt.Println(err2)
	}
	fmt.Println(at) //6
	defer file.Close()
}
